//
//  GCMChaoBiaoTableViewCell.m
//  GeeCityManager
//
//  Created by 聚城科技 on 16/10/9.
//  Copyright © 2016年 聚城科技. All rights reserved.
//

#import "GCMChaoBiaoTableViewCell.h"
#import "PPNumberButton.h"

@implementation GCMChaoBiaoTableViewCell{
    
    UIView * _bgView;
    UILabel *_roomLabel;
    UILabel *_zhuangtaiLabel;
    UILabel *_chaobiaoLabel;
    UILabel *_typeLabel;
    UILabel *_benMonthLabel;
    UILabel *_shangMonthLabel;
    UILabel *_benqiMonthLabel;
    PPNumberButton *_numberButton;
    
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self createUI];
    }
    return self;
}

-(void)createUI{
    
    _bgView = [[UIImageView alloc]init];
    _bgView.frame =CGRectMake(10, 5,SCREEN_WIDTH - 20, SCREEN_HEIGHT/3 - 10);
    _bgView.backgroundColor = [UIColor whiteColor];
    _bgView.userInteractionEnabled = YES;
    [self.contentView addSubview:_bgView];
    
    
    _roomLabel = [[UILabel alloc]init];
    _roomLabel.frame = CGRectMake(20,0,_bgView.bounds.size.width - 40, _bgView.bounds.size.height/31*8 - 1);
    _roomLabel.textAlignment = NSTextAlignmentLeft;
    _roomLabel.font = [UIFont systemFontOfSize:15];
    [_bgView addSubview:_roomLabel];
    _zhuangtaiLabel = [[UILabel alloc]init];
    _zhuangtaiLabel.frame = CGRectMake((_bgView.bounds.size.width - 40)/2,0,(_bgView.bounds.size.width - 40)/2 + 20, _bgView.bounds.size.height/31*8 - 1);
    _zhuangtaiLabel.textAlignment = NSTextAlignmentRight;
    _zhuangtaiLabel.textColor = [UIColor colorWithRed:0.00 green:0.63 blue:0.83 alpha:1.00];
    _zhuangtaiLabel.font = [UIFont systemFontOfSize:14];
    [_bgView addSubview:_zhuangtaiLabel];
    UILabel *lab1 = [[UILabel alloc]initWithFrame:CGRectMake(20,_bgView.bounds.size.height/31*8, _bgView.bounds.size.width - 40, 2)];
    lab1.layer.borderWidth = 2;
    lab1.layer.borderColor = [[UIColor colorWithRed:0 green:0.63 blue:0.83 alpha:1]CGColor];
    [_bgView addSubview:lab1];
    
    _typeLabel = [[UILabel alloc]init];
    _typeLabel.frame = CGRectMake(20 ,_bgView.bounds.size.height/31*8 +3 , (_bgView.bounds.size.width - 40)/2, _bgView.bounds.size.height/31*5 - 2);
    _typeLabel.font = [UIFont systemFontOfSize:14];
//    _typeLabel.text = @"水表";
    _typeLabel.textColor = [UIColor colorWithRed:0.58 green:0.65 blue:0.65 alpha:1.00];
    _typeLabel.textAlignment = NSTextAlignmentLeft;
    [_bgView addSubview:_typeLabel];
    UILabel *lab2 = [[UILabel alloc]initWithFrame:CGRectMake(20,_bgView.bounds.size.height/31*14, _bgView.bounds.size.width - 40, 1)];
    lab2.layer.borderWidth = 1;
    lab2.layer.borderColor = [[UIColor colorWithRed:0.94 green:0.94 blue:0.95 alpha:1]CGColor];
    [_bgView addSubview:lab2];
    
//    本期读数
    _benMonthLabel = [[UILabel alloc]init];
    _benMonthLabel.frame = CGRectMake(20,_bgView.bounds.size.height/31*14, _bgView.bounds.size.width - 40,_bgView.bounds.size.height/31*8 );
    _benMonthLabel.font = [UIFont systemFontOfSize:14];
    _benMonthLabel.textAlignment = NSTextAlignmentLeft;
    _benMonthLabel.text = @"本期读数";
    _benMonthLabel.textColor = [UIColor colorWithRed:0.58 green:0.65 blue:0.65 alpha:1.00];
    [_bgView addSubview:_benMonthLabel];
    _benqiMonthLabel = [[UILabel alloc]init];
    _benqiMonthLabel.frame = CGRectMake((_bgView.bounds.size.width - 40)/2, _bgView.bounds.size.height/31*14 +10, (_bgView.bounds.size.width - 40)/2, _bgView.bounds.size.height/31*8 - 20);
    _benqiMonthLabel.font = [UIFont systemFontOfSize:14];
    _benqiMonthLabel.textAlignment = NSTextAlignmentCenter;
    _benqiMonthLabel.textColor = [UIColor colorWithRed:0.58 green:0.65 blue:0.65 alpha:1.00];
    [_bgView addSubview:_benqiMonthLabel];
    _numberButton = [[PPNumberButton alloc] initWithFrame:CGRectMake((_bgView.bounds.size.width - 40)/2, _bgView.bounds.size.height/31*14 +10, (_bgView.bounds.size.width - 40)/2, _bgView.bounds.size.height/31*8 - 20)];
    __weak typeof(self) weakSelf = self;
    [_numberButton setNumberBlock:^(NSString *number) {
        weakSelf.textChangedBlock ? weakSelf.textChangedBlock(number) : nil;
    }];
    //设置边框颜色
    _numberButton.borderColor = [UIColor grayColor];
    [_bgView addSubview:_numberButton];
    UILabel *lab3 = [[UILabel alloc]initWithFrame:CGRectMake(20,_bgView.bounds.size.height/31*22, _bgView.bounds.size.width - 40, 1)];
    lab3.layer.borderWidth = 1;
    lab3.layer.borderColor = [[UIColor colorWithRed:0.94 green:0.94 blue:0.95 alpha:1]CGColor];
    [_bgView addSubview:lab3];
    
//    上期读数
    UILabel *lab= [[UILabel alloc]init];
    lab.frame = CGRectMake(20,_bgView.bounds.size.height/31*22, _bgView.bounds.size.width - 40,_bgView.bounds.size.height/31*8);
    lab.font = [UIFont systemFontOfSize:14];
    lab.textAlignment = NSTextAlignmentLeft;
    lab.textColor = [UIColor colorWithRed:0.58 green:0.65 blue:0.65 alpha:1.00];
    lab.text = @"上期读数";
    [_bgView addSubview:lab];
    _shangMonthLabel= [[UILabel alloc]init];
    _shangMonthLabel.frame = CGRectMake((_bgView.bounds.size.width - 40)/2,_bgView.bounds.size.height/31*22, (_bgView.bounds.size.width - 40)/2,_bgView.bounds.size.height/31*8);
    _shangMonthLabel.font = [UIFont systemFontOfSize:14];
    _shangMonthLabel.textAlignment = NSTextAlignmentCenter;
    _shangMonthLabel.textColor = [UIColor colorWithRed:0.58 green:0.65 blue:0.65 alpha:1.00];
    [_bgView addSubview:_shangMonthLabel];
    UILabel *lab4 = [[UILabel alloc]initWithFrame:CGRectMake(20,_bgView.bounds.size.height/31*30, _bgView.bounds.size.width - 40, 1)];
    lab4.layer.borderWidth = 1;
    lab4.layer.borderColor = [[UIColor colorWithRed:0.94 green:0.94 blue:0.95 alpha:1]CGColor];
    [_bgView addSubview:lab4];
    

    
}

-(void)setChabiaoModel:(GCMChaobiaoModel *)chabiaoModel{
    __weak typeof(self)weakSelf = self;
    _chabiaoModel = chabiaoModel;
    _shangMonthLabel.text = _chabiaoModel.syds;
    _benqiMonthLabel.text = _chabiaoModel.byds;
    _roomLabel.text = [NSString stringWithFormat:@"房间号:%@   %@" ,_chabiaoModel.room ,_chabiaoModel.yzmc];
    if ([_chabiaoModel.valid isEqualToString:@"1"]) {
        _zhuangtaiLabel.text = @"(未抄表)";
        _numberButton.hidden = NO;
        _benqiMonthLabel.hidden = YES;
        
    }else{
        _zhuangtaiLabel.text = @"(已抄表)";
        if ([self.erjiPage isEqualToString:@"2"]) {
            _numberButton.hidden = NO;
            _benqiMonthLabel.hidden = YES;
        }else{        
            _numberButton.hidden = YES;
            _benqiMonthLabel.hidden = NO;
        }
    }
    _typeLabel.text = [NSString stringWithFormat:@"抄表类型：%@",_chabiaoModel.biao ];
    UITextField * textfield = (UITextField *)[weakSelf.contentView viewWithTag:5566];
    if (![_chabiaoModel.byds isEqualToString:@"0"]) {
        textfield.text = _chabiaoModel.byds;
    }else{
        textfield.text = _chabiaoModel.syds;
    }
    
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
